package com.study.jyg.rxjava2study.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

public class AbsChart extends View {
    public AbsChart(Context context) {
        super(context);
    }

    public AbsChart(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public AbsChart(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }
    public float getViewWidth(){
        ViewGroup.LayoutParams params = getLayoutParams();
        if (params == null){
            params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        int widthSpec = ViewGroup.getChildMeasureSpec(0,0,params.width);
        int heightSpec;
        if (params.height>0){
            heightSpec = View.MeasureSpec.makeMeasureSpec(params.height, View.MeasureSpec.EXACTLY);
        }else {
            heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
        }
        measure(widthSpec,heightSpec);
        return getMeasuredWidth();//获取布局高度，获取布局宽度可以调用getMeasuredWidth()
    }
}
